import {
  upgrade, ended,getPeriod
} from '../../api/groupOrder';
import {
  getInfo,
} from '../../api/member'
Component({
  lifetimes: {
    attached() {
      this.getInfo()
    }
  },
  properties: {
    orderData:{
      type: Object,
      value: '',
    },
    noDataImg: {
      type: String,
      value: '',
    },
    noDataText: {
      type: String,
      value: '暂无数据',
    },
    loading: {
      type: Boolean,
      value: false,
    },
  },
  data: {
    relationshipType:true,
    logo:'',
    dialogType:false,
    inputData:'',
    period:{},
    avatar:null
  },

  methods: {
    getInfo() {
      getInfo().then(res => {
        this.data.avatar  = res.data.member.avatar
            this.setData({
              avatar:this.data.avatar
            })
      })
    },
    getPeriodClick(groupOrderId){
      let params = {
        id:groupOrderId
      }
      getPeriod(params).then(res=>{
        this.data.period =res.data
        this.data.dialogType = true
        this.setData({
          period: this.data.period,
          dialogType:this.data.dialogType
        })
      })
    },
    cloneClick(){
      this.data.dialogType = false
      this.setData({
        dialogType:this.data.dialogType
      })
    },
    saveClick(){
      var _this =  this
      upgrade({groupOrderId:_this.data.orderData.id}).then(res=>{
        wx.showToast({
          icon: "none",
          title: '参加抽奖成功'
        })
        _this.triggerEvent('loadList')
        this.data.dialogType = false
        this.setData({
          dialogType:this.data.dialogType
        })
      }).catch(res=>{
        this.data.dialogType = false
        this.setData({
          dialogType:this.data.dialogType
        })
      })
    },
    relationshipClick(){
      this.data.relationshipType = !this.data.relationshipType
      this.setData({
        relationshipType: this.data.relationshipType
      })
    },
    ticlick(){
      var _this = this
      wx.showModal({
        title: '提示:',
        content:'提现后将不能再参加抽奖活动',
        success (res) {
          if (res.confirm) {
            let params = {}
            params.groupOrderId = _this.data.orderData.id
            ended(params).then(res=>{
              wx.showToast({
                icon: "none",
                title: '提现成功'
              })
              _this.triggerEvent('loadList')
            })
          } else if (res.cancel) {
          }
        }
      })
    },
    upgradeclick(e){
      this.getPeriodClick(this.data.orderData.id)
    }
  }
})
